# Maintainer: Christian Rebischke <chris.rebischke@archlinux.org>
# Contributor: ml <>
pkgname=kubectl-cert-manager
pkgver=1.11.1
pkgrel=1
pkgdesc='Automatically provision and manage TLS certificates in Kubernetes'
arch=('loong64' 'x86_64' 'aarch64')
url='https://github.com/jetstack/cert-manager'
license=('Apache')
depends=('kubectl')
makedepends=('git' 'go')
groups=('kubectl-plugins')
source=("$url/archive/v$pkgver/$pkgname-$pkgver.tar.gz")
sha512sums=('a97065807ab390b3516375af916860c9b4a4d9ef1d0814b1c1d727ae6e05b0f05d37cce7b8a3d1db5558d28b745b3c7e671daf8f6f12aaa007d255e64c8ea6ac')
b2sums=('0202c6a6121803f753bc8984c880d12d6dbafbe91d9d1fa94384ff6bfdfded3d4a59d8c6b7308485b221609534872a58189df943d153123131c3106fd413f3e3')

build() {
  local _x _commit
  _commit=$(bsdcat "$pkgname-$pkgver.tar.gz" | git get-tar-commit-id)
  _x=(
    AppVersion="v$pkgver"
    AppGitCommit="${_commit:?}"
    AppGitState="clean"
  )

  cd cert-manager-"$pkgver"
  export CGO_ENABLED=1
  export CGO_LDFLAGS="$LDFLAGS"
  export CGO_CFLAGS="$CFLAGS"
  export CGO_CPPFLAGS="$CPPFLAGS"
  export CGO_CXXFLAGS="$CXXFLAGS"
  export GOFLAGS='-buildmode=pie -trimpath -modcacherw -mod=readonly'
  go build -ldflags="-linkmode=external ${_x[*]/#/-X=github.com/jetstack/cert-manager/pkg/util.}" ./cmd/ctl
}

check() {
  cd cert-manager-"$pkgver"
  # we don't want e2e and other tests that explicitly want bazel
  go test -short ./cmd/ctl/...
}

package() {
  cd cert-manager-"$pkgver"
  install -Dm755 ctl "$pkgdir"/usr/bin/kubectl-cert_manager
}
